<template>
	<view class="coach">
		<view class="dheader">
			<view class="shop">
				<image :src="shop_info.category_image" mode="aspectFill" class="Boutique"></image>
				<view class="title">
					{{shop_info.shop_name}}
				</view>
				<view class="right" @click="toggle">
					<view class="size">
						切换
					</view>
					<image :src="$IMG_URL('/static/home/indicate.png')" mode="" class="icon"></image>
				</view>
			</view>
			<view class="search">
				<u-search placeholder="搜索教练名称" :show-action="false" shape="square" v-model="query.search" @change="$u.debounce(getSearch,500)"></u-search>
			</view>
		</view>
		<scroll-view scroll-y="true" class="scroll-view-Y" @scrolltolower="scrolltolower">
			<view class="comlum_box" v-if="list.length">
				<view v-for="(item,index) in list" :key="index" class="item">
					<image :src="$IMG_URL('/static/shop/recommend.png')" mode="aspectFit" class="recommend"></image>
					<Oitem :query="item"></Oitem>
				</view>
				<u-loadmore :status="status" />
			</view>
			<empty v-else :content="'教练'"></empty>
		</scroll-view>
		<FieldPopupVue :popupShow="popupShow" :FieldList="Field" @sure="sure" @changeActiveIndex="changeActiveIndex"
			:activeIndex="FieldIndex"></FieldPopupVue>
	</view>
</template>

<script>
	import FieldPopupVue from '../../pages/user/components/Field-popup.vue'
	import Oitem from '@/components/coachItem.vue';
	import empty from './components/empty.vue'
	import{
		atShop,
		coachDetailsList
	} from '@/api/manager.js'
	export default {
		components: {
			FieldPopupVue,
			Oitem,
			empty
		},
		data(){
			return{
				// 切换门店
				popupShow: false,
				FieldIndex: -1,
				shop_info:{},
				query:{
					shop_id:'',
					search:'',
					page:1
				},
				list:[],
				status: 'loadmore', //当前状态
			}
		},
		onLoad() {
			this.getatShop()
			this.getcoachList()
		},
		methods:{
			getSearch(){
				this.list = []
				this.query.page = 1
				this.getcoachList()			
			},
			scrolltolower(){
				this.query.page++
				this.getcoachList()
			},
			getcoachList(){
				coachDetailsList(this.query).then(({data:res})=>{
					console.log('res', res);
					if (res.code == 1) {
						const list = []
						this.status = 'loading'
						if (this.query.page > res.data.all_page) {
							console.log('nomore');
							this.status = 'nomore'
							return false
						} else {
							console.log('more');
							this.status = 'more'
							this.list = this.list.concat(res.data.list)
						}
					
						console.log('list', this.list);
					}
				})
			},
			getatShop(e){
				atShop(e).then(({data:res})=>{
					console.log('res', res);
					if(res.code == 1){
						this.shop_info = res.data
					}
				})
			},
			// 切换门店
			toggle() {
				console.log(11);
				this.popupShow = true
			},
			changeActiveIndex(item, index){
				this.FieldIndex = index
				this.getatShop({
					shop_id:item.shop_id
				})
				this.list = []
				this.query.page = 1
				this.getcoachList()
			},
			sure() {
				this.popupShow = false
			},
		}
	}
</script>

<style lang="scss" >
	page {
		background: #e9e9e9;
	}
	
	.coach {
		display: flex;
		flex-direction: column;
		align-items: center;
	
		.dheader {
			width: 750rpx;
			height: 184rpx;
			background: #ffffff;
			padding: 26rpx 34rpx 0;
	
			.shop {
				width: 100%;
				display: flex;
				flex-direction: row;
				align-items: center;
				margin-bottom: 22rpx;
	
				.Boutique {
					width: 114rpx;
					height: 36rpx;
					margin-right: 12rpx;
				}
	
				.title {
					flex: 1;
					font-size: 28rpx;
					font-family: PingFang SC, PingFang SC-Bold;
					font-weight: 700;
					text-align: left;
					color: #333333;
				}
	
				.right {
					display: flex;
					flex-direction: row;
					align-items: center;
	
					.size {
						font-size: 28rpx;
						font-family: PingFang SC, PingFang SC-Regular;
						font-weight: 400;
						color: #666666;
						margin-right: 8rpx;
					}
	
					.icon {
						width: 10rpx;
						height: 16rpx;
					}
				}
			}
	
			.search {
				width: 100%;
			}
	
	
		}
		.scroll-view-Y{
			height: 83vh;
			width: 100%;
			.comlum_box{
				display: flex;
				flex-direction: column;
				align-items: center;
				padding-top: 20rpx;
				.item{
					margin-bottom: 20rpx;
					width: 702rpx;
					height: 352rpx;
					background: #ffffff;
					border-radius: 16rpx;
					position: relative;
					padding: 20rpx;
					.recommend{
						position: absolute;
						top: 0;
						right: 0;
						width: 136rpx;
						height: 38rpx;
						z-index: 99;
						
					}
				}
			}
		}
	}	
</style>